package cn.com.egova.materialdesignexample;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import cn.com.egova.materialdesignexample.utils.JumpUtils;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
    private ListView lv;
    private JumpUtils jumpUtils;
    String[] items = {"TextInputLayout","DrawerLayout","NavigationView","Snackbar",
            "AppBarLayout","CollapsingToolbarLayout","CoordinatorLayout","FloatingActionButton",
            "RecyclerView","CardView"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        jumpUtils = new JumpUtils(this);

        initToolbar();

        initView();
    }

    private void initToolbar(){
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("Material示例");
        toolbar.setNavigationIcon(R.mipmap.icon_back);
        toolbar.setNavigationOnClickListener(new NavigationView.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    private void initView(){
        lv = (ListView) findViewById(R.id.listView);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,items){
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                TextView tv = (TextView) super.getView(position, convertView, parent);
                tv.setTextColor(Color.BLACK);
                return tv;
            }
        };
        lv.setAdapter(adapter);

        lv.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case  0:
                jumpUtils.goTextInputLayout();
                break;
            case  1:
                jumpUtils.goDrawerLayout();
                break;
            case  2:
                jumpUtils.goNavigationView();
                break;
            case  3:
                jumpUtils.goSnackbar();
                break;
            case  4:
                jumpUtils.goAppBarLayout();
                break;
            case  5:
                jumpUtils.goCollapsingToolbarLayout();
                break;
            case  6:
                jumpUtils.goCoordinatorLayout();
                break;
            case  7:
                jumpUtils.goFloatingActionButton();
                break;
            case  8:
                jumpUtils.goRecyclerView();
                break;
            case  9:
                jumpUtils.goCardView();
                break;
        }
    }
}
